/*
 * ArCoLIVE - Live Internet Videoconference Environment
 * Information Technology Departament - Federal University of Alagoas - Brazil
 *
 * Copyright (C) 2005 Leandro Melo de Sales (leandro@labpesquisas.tci.ufal.br)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
package br.ufal.tci.nexos.arcolive.participant;

import java.util.ArrayList;
import java.util.Iterator;

import br.ufal.tci.nexos.arcolive.exception.ArCoLIVECannotAddParticipantInGroupException;

/**
 * CLASSNAME.java
 *
 * CLASS DESCRIPTION
 *
 * @see CLASSNAME
 *
 * @author <a href="mailto:felipe@labpesquisas.tci.ufal.br">Felipe Barros Pontes</a>.
 * @author <a href="mailto:leandro@labpesquisas.tci.ufal.br">Leandro Melo de Sales</a>.
 * @since 0.1
 * @version 0.1
 *
 * <p><b>Revisions:</b>
 *
 * <p><b>yyyymmdd USERNAME:</b>
 * <ul>
 * <li> VERSION
 * </ul>
 */
public class ArCoLIVEParticipantGroup {

	private ArrayList participants;
	private int maxParticipantSize;
	
	public ArCoLIVEParticipantGroup(int maxParticipantSize) {
		this.participants = new ArrayList(maxParticipantSize);
		this.maxParticipantSize = maxParticipantSize;
	}
	
	public void addParticipant(ArCoLIVEParticipant participant) throws ArCoLIVECannotAddParticipantInGroupException {
		if (this.participants.size()+1 <= this.maxParticipantSize || this.maxParticipantSize == 0) {
			if (!this.participants.contains(participant)) {
				this.participants.add(participant);
			}
		} else {
			throw new ArCoLIVECannotAddParticipantInGroupException("Max user in group reached");
		}
	}
	
	public void removeParticipant(ArCoLIVEParticipant participant) {
		this.participants.remove(participant);
	}
	
	public int getSize() {
		return this.participants.size();
	}
	
	public int getMaxParticipantSize() {
		return this.maxParticipantSize;
	}
	
	public void setMaxParticipantSize(int maxParticipantSize) {
		this.maxParticipantSize = maxParticipantSize;
	}
	
	public ArCoLIVEParticipant[] getParticipants() {
		ArCoLIVEParticipant participants[] = new ArCoLIVEParticipant[this.participants.size()];
		int i=0;
		for (Iterator iter = this.participants.iterator(); iter.hasNext(); i++) {
			participants[i] = (ArCoLIVEParticipant) iter.next();
		}
		return participants;
	}
	
	public boolean isInParticipantGroup(ArCoLIVEParticipant participant) {
		return this.participants.contains(participant);
	}
	
}
